#include "carWash.h"

carWash::carWash()
{
	bayfull = false;
	numline = 5;
	wash = 10;
}

void carWash::runSimulation()
{
	int time=0; //holds current arrival time
	washed = 0;
	lostCars = 0;

	time = temp.get_arrivalTime();

	while (time != 999)
	{	
		//Check to see if there are any cars in wait line
		if (customer.size() == 0 && !bayfull)
		{
			bayfull = true;
			baytime = time;
			cout<<"\nCar entered the bay\n";
			washed++; //Number of cars washed
		}
		else if ((baytime+wash) <= time)
		{
			bayfull = false;
			cout<<"Car left the bay at "<<baytime+wash<<endl;
			baytime = time;
			cout<<"Car entered the bay at "<<baytime;
			
			//If there is the car in line to the bay and add new car to the line
			if(!customer.size() == 0)
			{	
				baytime = temp.show();
				cout<<"bay time is "<<baytime<<endl;
				customer.pop();
				customer.push(time);
				cout<<"Car entered the waiting line\n";
			}

			bayfull = true;
			washed++;
		}
		else if ((baytime+wash) >= time)
		{	
			if(customer.size() > 0 && customer.size() < numline)
			{	
				//If there is already a line put the car in the line
				customer.pop();
				customer.push(time);
			}
			else if (customer.size() == numline)
			{
				//If the line is full car drives away and add 1 to lost cars
				lostCars++;
			}
			else
			{
				cout<<"Car added to waiting line\n";
				customer.push(time);
			}

			if (!customer.size() == 0)
			{	
				customer.pop(); //Remove the first person in line
				customer.push(time);
			}
			washed++;
			
		}
		
		time = temp.get_arrivalTime();
	}
	show_results(); 
}

void carWash::show_results()
{
	cout<<"Total cars washed: "<<washed<<" car(s)\n";
	cout<<"The number of cars that we lost money on was "<<lostCars<<" car(s)"<<endl;

}
